Setting materials for rendering

In Kanzi you can use these render passes to set materials for rendering:

Creating a night vision mode

You can use the Draw Objects With Material Render Pass to render all nodes under a Scene node with a specific material. For example, you can create a night vision mode.

To create a night vision mode:

  1. Create the content that you want to render in night vision mode.
    For example, use the Car from the Factory Content. See Using the Factory Content assets.
  2. Create and apply the render passes that you need to render the content in night vision mode:
    1. In the Library > Rendering press Alt and right-click Render Passes, select Group Render Pass, and name it Night Vision.
      You use this Group Render Pass to collect the render passes which apply the night vision mode to your content.
    2. In the Project select the Scene node the content of which you want to render in night vision mode, and in the Properties set the Render Pass property to the Night Vision render pass.
      This way you set Kanzi to render the Scene node using the Night Vision render pass. The Night Vision render pass does not have any child render passes, which is why the Preview does not show any content.
    3. In the Night Vision render pass create:
      1. Clear Render Pass
      2. Draw Objects With Material Render Pass
      You can use a Draw Objects With Material Render Pass render pass to render all nodes under a Scene node with a specific material that you set in the Draw Objects With Material Render Pass.
      Because you have not yet set the Material property in the Draw Objects With Material Render Pass, Kanzi uses the default materials to render the content in the Scene node which uses the Night Vision render pass.
  3. Create the material that you want to use for the night vision mode.
    For example, in the Library > Materials and Textures > Material Types press Alt and right-click VertexPhong, select Material, and name the material Night Vision Material.
    This way you create a material which uses the VertexPhong material type.
  4. In the Library > Rendering > Render Passes select the Draw Objects With Material Render Pass and in the Properties set the Material property to the material you created in the previous step.
    Kanzi now renders all nodes in the Scene node, which uses the Night Vision render pass, with the material that you created.

  5. In the Properties click the next to the Material property to open the properties of the material that you created, and set the properties of the material to achieve the look you want.

  6. In the Library > Rendering > Render Passes select the Clear Render Pass, in the Properties add the Clear Color property, and set the Lightness (L) property field to 0.
    This way you clear the color buffer with black color to make the background of your scene black in the night vision mode.
  7. Control the switching between the day and night vision modes.
    For example, create a State Manager where you define states for:

    See Creating a state manager.

    Now when you switch between the states you created, Kanzi alternates between rendering your content normally and in night vision mode.

Creating an infinity mirror

Material Setup Render Pass allows you to set properties for a material so that all successive rendering with that material uses the property values you set in this render pass. For example, you can use the Material Setup Render Pass to create an infinity mirror effect.

To create an infinity mirror:

  1. In the Project create:
  2. Create the material that you use to render the 3D content in the mirror:
    1. Create a textured material.
      For example, in the Library > Materials and Textures > Material Types press Alt and right-click Textured, select Material, and name the material Mirror Material.
    2. In the Project select the node that you want to use as the mirror and in the Properties set the Mesh Material property to the material you created in the previous step.
  3. Render the 3D content in the mirror:
    1. In the Library press Alt and right-click Rendering, and select Compose and Blit Pass.
      Compose and Blit Pass template contains the render pass structure that enables you to blit to the screen Composition Target Render Pass render passes or textures using a specific material. The template contains these render passes:
      • Composition Target Render Pass renders itself and its child render passes to a composition target.
        • Clear Render Pass clears some or all of the buffers of the current render context. By default the Clear Render Pass in the Compose and Blit Pass template clears the color buffer with transparent black color and the depth buffer with value 1.
          For example, to clear the color buffer with a different color, set the Clear Color property to the color that you want to use as the background color of the content that Kanzi renders to the Composition Target Render Pass.
        • Draw Objects Render Pass allows you to set a Camera node to render a specific object source and to control frustum culling. By default the Draw Objects Render Pass uses the default Camera node to render all nodes in a Scene node.
      • Blit Render Pass blits one or more render passes or textures on the screen using a specific material. By default this Blit Render Pass draws on the screen the content rendered by the Composition Target Render Pass.
    2. In the Library select the Compose and Blit Pass > Composition Target Render Pass > Clear Render Pass and in the Properties set the Clear Color property to the color that you want to use as the background color of the scene in the mirror.
    3. In the Project select the Scene node the content of which you want to render in the mirror, and in the Properties set the Render Pass property to the Compose and Blit Pass.
      This way you set Kanzi to render the Scene node using the Compose and Blit Pass.
    4. In the Library in the Compose and Blit Pass create a second Composition Target Render Pass and drag the Blit Render Pass to that Composition Target Render Pass.
      You use the second Composition Target Render Pass to render the first Composition Target Render Pass to a composition target.
      You create two Composition Target Render Pass render passes because the rendering behavior is undefined if you simultaneously write to and read from the same render pass.

    5. In the Compose and Blit Pass create a Default Render Pass.
      Default Render Pass creates a basic set of render passes that first render opaque nodes and then transparent nodes.
      You use this render pass to render to the screen the content of the Scene node.
    6. In the Compose and Blit Pass create a Material Setup Render Pass and in the Properties add and set:
      • Material to the material that you created earlier in this procedure.
        For example, set it to Mirror Material.
      • Texture to the second Composition Target Render Pass that you created.
        For example, set it to Composition Target Render Pass 2.
        Here you set the value of the Texture property for the material that you created, so that Kanzi uses the value when rendering content using the Compose and Blit Pass.
      This way you set Kanzi to render the Composition Target Render Pass 2 in the node that uses the Mirror Material.

Kanzi now recursively renders the contents of the scene in the mirror.

See also

Rendering

Using materials